package cn.smart.epic.core.listener;

import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;

/**
 * @Auther Uncle_Z
 * @date 2018/8/6 16:24
 * @Email:2545375@qq.com
 * @Descrition
 * @since 1.0
 */

public class RequestFilter implements Filter {
    @Override
    public void init(FilterConfig filterConfig) throws ServletException {

    }

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest requestwarpper = null;
        if(request instanceof HttpServletRequest){
            HttpServletRequest httpServletRequest = ((HttpServletRequest) request);
            requestwarpper = new BodyReaderHttpServletRequestWrapper(httpServletRequest);
        }

        if(requestwarpper == null){
            chain.doFilter(request,response);
        }else{
            chain.doFilter(requestwarpper,response);
        }
    }

    @Override
    public void destroy() {

    }
}
